﻿using Quartz;
using Quartz.Impl.Triggers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZhouYu.DreamTour.Core;

namespace ZhouYu.DreamTour.WinService.Common
{
    public class JobschedulerManager
    {
        /// <summary>
        /// 添加调度
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sched"></param>
        /// <param name="croname"></param>
        /// <param name="trigroup"></param>
        /// <param name="trigGroupName"></param>
        public static void AddScheduler<T>(ref IScheduler sched, string croname, string trigroup, string trigGroupName) where T : IJob
        {
            var jobKey = new JobKey(croname + "key", trigroup);
            //创建调度服务
            File.AppendAllText("D:\\Log.txt", "创建调度服务");
            var jobDetail = JobBuilder.Create<T>().WithIdentity(jobKey).Build();
            //设置调度时间间隔
            var jobTrig = new CronTriggerImpl(croname + "Trig", trigGroupName, ConfigurationHelper.GetSectionValue("Crons", croname));
            File.AppendAllText("D:\\Log.txt", "设置调度时间间隔");

            sched.ScheduleJob(jobDetail, jobTrig);
            File.AppendAllText("D:\\Log.txt", "123456");
        }
    }
}
